package com.example.administrator.asdasd;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2016/3/31.
 */
public class New_user extends AppCompatActivity {
    private EditText et1;
    private EditText et2;
    private EditText et3;
    private EditText et4;
    private EditText et5;
    private EditText et6;
    private EditText et7;
    private TextView tt1;
    public String user_name;
    private Button new_btn;
    private int flag;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user);
        et1 = (EditText) findViewById(R.id.editName);
        et2 = (EditText) findViewById(R.id.editNum);
        et3 = (EditText) findViewById(R.id.editMax);
        et4 = (EditText) findViewById(R.id.editWeizhi);
        et5 = (EditText) findViewById(R.id.oldPassword);
        et6 = (EditText) findViewById(R.id.newPassword);
        tt1 = (TextView) findViewById(R.id.userId);
        user_name = getIntent().getStringExtra("name");
        tt1.setText(user_name);
        new_btn = (Button) findViewById(R.id.edit);

        new_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SQLdm s = new SQLdm();
                SQLiteDatabase db = s.openDatabase(getApplication());
                Cursor c = db.rawQuery("select * from grtb where name=?", new String[]{user_name});

                String str =new String();
                while(c.moveToNext())
                {
                    str = c.getString(c.getColumnIndex("password"));
                }
                if(str.equals(et5.getText().toString()))
                {
                    ContentValues val =new ContentValues();
                    val.put("ren_name",et1.getText().toString());
                    val.put("num",et2.getText().toString());
                    val.put("max",et3.getText().toString());
                    val.put("weizhi",et4.getText().toString());
                    db.update("grtb", val, "name=?", new String[]{user_name});
                    Toast.makeText(getApplicationContext(),"修改成功",Toast.LENGTH_SHORT).show();
                    finish();
                }
                else
                {
                    Toast.makeText(getApplicationContext(),"原密码输入错误请重新输入",Toast.LENGTH_SHORT).show();
                }
                finish();
            }
        });

    }
}
